package com.xiweicheng.test.springboot.jpa;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface ProjectRepository extends JpaRepository<Project, Long>, JpaSpecificationExecutor<Project> {

	@Query("select u from #{#entityName} u where u.name like %?1%")
	List<Project> findByName(String name);

	@Transactional
	@Modifying
	@Query("update #{#entityName} u set u.name = ?1 where u.id = ?2")
	int updateName(String name, Long id);

	@Transactional
	void deleteById(Long id);

	@Transactional
	@Modifying
	@Query("delete from #{#entityName} u where u.id = ?1")
	void deleteById2(Long id);

}
